import request from './index'

// 获取问诊列表
export function getConsultations() {
  return request({
    url: '/consultations',
    method: 'get',
  })
}

// 创建问诊订单
export function createConsultation(data) {
  // 确保数据格式正确
  const formattedData = {
    patient_name: data.patient_name,
    phone: data.phone,
    date: data.date,
    time: data.time,
    address: data.address,
    service_type: data.service_type,
    total_price: data.total_price,
    selected_services: data.selected_services || [],
    order_type: data.order_type,
    accompany_type: data.accompany_type,
    hospital_name: data.hospital_name,
    department: data.department,
  }

  console.log('发送预约请求数据:', formattedData)
  console.log('本地存储的 token:', localStorage.getItem('token'))

  return request({
    url: '/consultations',
    method: 'post',
    data: formattedData,
  })
}

// 更新问诊状态
export function updateConsultationStatus(consultationId, status) {
  return request({
    url: `/consultations/${consultationId}/status`,
    method: 'put',
    data: { status },
  })
}

// 获取我的问诊列表
export function getMyConsultations() {
  return request({
    url: '/consultations',
    method: 'get',
  })
}
